using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class barbette : Creation
{
    private Rigidbody2D myRigidbody;
    public float healthratio;

    public float CD;
    float CDtime;
    public GameObject ballet;
    Transform transform;
    public float dietime = 30f;
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        //enemyattack= attackobject.GetComponent<EnemyAttack> ();
        //face = enemyattack.face;
        transform = GetComponent<Transform>();
        face = GameObject.FindWithTag("Player").GetComponent<PlayerBasic>().face;
        if(face>0)transform.localRotation= Quaternion.Euler(0, 180, 0);
        CDtime = CD;
        health=healthratio* GameObject.FindWithTag("Player").GetComponent<PlayerBasic>().health;
    }
    public override void TakeDamage(float damage)
    {
        health -= damage;
        if (health <= 0)
            Destroy(gameObject);
    }
    // Update is called once per frame
    void Update()
    {
        if (dietime < 0)
        {
            Destroy(gameObject);
        }
        dietime -= Time.deltaTime;
        if (CDtime > 0)
        {
            CDtime -= Time.deltaTime;
        }
        else
        {
            CDtime = CD;
            Vector3 vector = transform.position;
            vector.x -= face * 1f;
            vector.y += 0.155f;
            Instantiate(ballet, vector, Quaternion.identity,transform);
        }
    }
}
